﻿using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Threading;
using System.Windows.Threading;

namespace WPP_Console
{
    /// <summary>
    /// Interaction logic for the splash window
    /// </summary>
  
    public partial class SplashWindow : Window
    {
        //initializing variables
        Thread loadingThread; 
        Storyboard Displaytext; 
        Storyboard Hidetext;
        private delegate void ShowDelegate(string txt);
        private delegate void HideDelegate();
        ShowDelegate showDelegate;
        HideDelegate hideDelegate;

        /// <summary>
        /// Give varibles value
        /// </summary>
        public SplashWindow()
        {
            InitializeComponent();
            showDelegate = new ShowDelegate(this.showText);
            hideDelegate = new HideDelegate(this.hideText);
            Displaytext = this.Resources["showStoryBoard"] as Storyboard;
            Hidetext = this.Resources["HideStoryBoard"] as Storyboard;

        }
        
        /// <summary>
        /// Describe on events to happen on windowLoaded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            loadingThread = new Thread(load);
            loadingThread.Start();
        }

        /// <summary>
        /// called when loading
        /// </summary>
        private void load()
        {
            /**--the code below can be reused and added as text is needed.
            Thread.Sleep(2000);
            this.Dispatcher.Invoke(showDelegate, "Some text");
            Thread.Sleep(2000);
            this.Dispatcher.Invoke(hideDelegate); //load data
            //--end repeat if needed**/
           
            Thread.Sleep(1000);
            this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { Close(); }); //close the window
        }

        /// <summary>
        /// Display the predefined textboxes on command
        /// </summary>
        /// <param name="txt">text in the textbox</param>
        private void showText(string txt)
        {
            txtLoading.Text = txt;
            BeginStoryboard(Displaytext);
        }
        /// <summary>
        /// Hide the textboxes on command
        /// </summary> 
        private void hideText()
        {
            BeginStoryboard(Hidetext);
        }

    }
}
